package com.cmfi.utils;

import java.util.Map;

import com.alibaba.druid.util.StringUtils;

/**
 * Description SQL拼装工具类
 * @author Lenovo
 *
 */
public class SqlAssembly {
	/**
	 * Description 通过参数条件生成where语句
	 * @param date
	 * @param status
	 * @return
	 */
	public static String generateWhereConditionsByParams(Map<String, String> paramMap) {
		if (paramMap.isEmpty()) {
			return "";
		}
		String conditions = " where ";
		for (Map.Entry<String, String> entry : paramMap.entrySet()) {
			String key = entry.getKey();
			String value = entry.getValue();
			if (conditions.contains("=")) {
				if (!StringUtils.isEmpty(key)) {
					conditions = conditions + " and " + key + "=\"" + value + "\" ";
				}
			} else {
				conditions = conditions + " " + key + "=\"" + value + "\" ";
			}
		}
		return conditions;
	}
	
	/**
	 * Description 通过参数条件生成limit语句
	 * 
	 * @param date
	 * @param status
	 * @return
	 */
	public static String generateLimitCondition(long start, long pageSize) {
		return " limit " + start + "," + pageSize + " ";
	}

	/**
	 * Description 通过参数条件生成order by语句
	 * 
	 * @param date
	 * @param status
	 * @return
	 */
	public static String generateOrderByCondition(String param) {
		return " order by " + param + " ";
	}
}
